package com.test.component;

import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Set;

public class SomeBean {

    @Value("${request.timeout}")
    private int timeout;

    @ApolloConfigChangeListener
    private void someChangeHandler(ConfigChangeEvent changeEvent) {
//        if(changeEvent.isChanged("timeout")) {
           Set<String> keys = changeEvent.changedKeys();
           for(String key : keys) {
               System.out.println("change key :" + key);
               ConfigChange configChange = changeEvent.getChange(key);
              String oldVal = configChange.getOldValue();
              String newVal = configChange.getNewValue();
              System.out.println(oldVal + ";" + newVal);
           }

    }

    public int getTimeout() {
        return timeout;
    }

}
